<template>
<div class="user">
    <div class="common-form d-s-c"><span>{{$t('plus.settings')}}</span></div>
    <div class="p20">
      <el-form ref="form" size="small" label-width="160px">
        <el-form-item :label="$t('plus.enable_event')" prop="isOpen"
          ><el-switch v-model="form.isOpen"></el-switch
        ></el-form-item>
        <el-form-item :label="$t('plus.enable_distribution1')" prop="isAgent"
          ><el-switch v-model="form.isAgent"></el-switch
        ></el-form-item>
        <!--提交-->
        <div class="common-button-wrapper">
          <el-button type="primary" @click="onSubmit" :loading="loading"
            >{{$t('plus.submit')}}</el-button
          >
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import PointProductApi from "@/api/pointproduct.js";
export default {
  data() {
    return {
      form: {
        /*是否开启活动*/
        isOpen: false,
        /*是否开启分销*/
        isAgent: false
      },
      loading: false
    };
  },
  created() {
    /*获取数据*/
    this.getData();
  },
  methods: {
    /*获取数据*/
    getData() {
      let self = this;
      PointProductApi.getConfig({}, true).then(res => {
        self.form = res.data;
      }).catch(error => {});
    },
    /*提交保存*/
    onSubmit() {
      let self = this;
      let params = self.form;
      self.loading = true;
      PointProductApi.saveConfig(params, true).then(data => {
        self.loading = false;
        ElMessage({
          message: $t("plus.save_success"),
          type: "success"
        });
        self.getData();
      }).catch(error => {
        self.loading = false;
      });
    }
  }
};
</script>

